﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using LiveCharts.Charts;
using LiveCharts.Configurations;
using LiveCharts.Definitions.Series;
using LiveCharts.Dtos;
using LiveCharts.Helpers;
using LiveCharts.SeriesAlgorithms;
using LiveCharts.Wpf;
using LiveCharts.Wpf.Charts.Base;
using LiveCharts.Wpf.Components;

namespace LiveCharts.Wpf
{
    public class GearedValues<T> : NoisyCollection<T>, IChartValues, INoisyCollection, IList, ICollection, IEnumerable, INotifyPropertyChanged, IGearedValues, INotifyCollectionChanged, IDisposable
    {
        /// <summary>
        /// 数据点上移动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChartPointMove(object sender, MouseEventArgs e)
        {
            if ((DateTime.Now - this.dateTime_0).TotalMilliseconds < 50.0)
            {
                return;
            }
            this.dateTime_0 = DateTime.Now;
            Chart chart = sender as Chart;
            ChartPoint chartPoint = GetNearPoint(chart, e.GetPosition(chart.DrawMargin));
            if (chartPoint == null)
            {
                if (this.chartPoint_0 != null)
                {
                    ChartPointLeave(this.chartPoint_0, chart);
                }
                this.chartPoint_0 = null;
                return;
            }
            ChartPointLeave(this.chartPoint_0, chart);
            ChartPointHover(chartPoint, chart);
            this.chartPoint_0 = chartPoint;
        }
        /// <summary>
        /// 数据点点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChartPointClick(object sender, MouseButtonEventArgs e)
        {
            Chart chart = sender as Chart;
            ChartPoint chartPoint = GetNearPoint(chart, e.GetPosition(chart.DrawMargin));
            if (chartPoint == null)
            {
                return;
            }
            chart.OnDataClick(chartPoint.View, chartPoint);
        }
        /// <summary>
        /// 获取鼠标附近的数据点
        /// </summary>
        /// <param name="chart_1"></param>
        /// <param name="point_0"></param>
        /// <returns></returns>
        private static ChartPoint GetNearPoint(Chart chart_1, Point point_0)
        {
            return chart_1.ActualSeries
                .SelectMany((iseriesView_0) => iseriesView_0.Values.GetPoints(iseriesView_0))
                .FirstOrDefault((ChartPoint chartPoint_0) => chartPoint_0.View != null && chartPoint_0.View.ValidArea.Left < point_0.X && chartPoint_0.View.ValidArea.Left + chartPoint_0.View.ValidArea.Width > point_0.X && chartPoint_0.View.ValidArea.Top < point_0.Y && chartPoint_0.View.ValidArea.Top + chartPoint_0.View.ValidArea.Height > point_0.Y);
        }
        /// <summary>
        /// 数据点上移动
        /// </summary>
        /// <param name="chartPoint_1"></param>
        /// <param name="chart_1"></param>
        /// <exception cref="LiveChartsException"></exception>
        private static void ChartPointHover(ChartPoint chartPoint_1, Chart chart_1)
        {
            chart_1.TooltipTimeoutTimer.Stop();
            if (chartPoint_1 == null)
            {
                return;
            }
            if (chart_1.Hoverable)
            {
                chartPoint_1.View.OnHover(chartPoint_1);
            }
            if (chart_1.DataTooltip != null)
            {
                if (chart_1.DataTooltip.Parent == null)
                {
                    Panel.SetZIndex(chart_1.DataTooltip, int.MaxValue);
                    chart_1.TooltipContainer = new Popup
                    {
                        AllowsTransparency = true,
                        Placement = PlacementMode.RelativePoint
                    };
                    chart_1.AddToView(chart_1.TooltipContainer);
                    chart_1.TooltipContainer.Child = chart_1.DataTooltip;
                    Canvas.SetTop(chart_1.DataTooltip, 0.0);
                    Canvas.SetLeft(chart_1.DataTooltip, 0.0);
                }
                IChartTooltip chartTooltip = chart_1.DataTooltip as IChartTooltip;
                if (chartTooltip == null)
                {
                    throw new LiveChartsException("The current tooltip is not valid, ensure it implements IChartsTooltip");
                }
                if (chartTooltip.SelectionMode == null)
                {
                    chartTooltip.SelectionMode = new TooltipSelectionMode?(chartPoint_1.SeriesView.Model.PreferredSelectionMode);
                }
                TooltipDataViewModel tooltipData = ChartFunctions.GetTooltipData(chartPoint_1, chart_1.Model, chartTooltip.SelectionMode.Value);
                IChartTooltip chartTooltip2 = chartTooltip;
                TooltipData tooltipData2 = new TooltipData();
                tooltipData2.XFormatter = tooltipData.XFormatter;
                tooltipData2.YFormatter = tooltipData.YFormatter;
                tooltipData2.SharedValue = tooltipData.Shares;
                tooltipData2.SelectionMode = (chartTooltip.SelectionMode ?? TooltipSelectionMode.OnlySender);
                tooltipData2.Points = tooltipData.Points.Select(new Func<ChartPoint, DataPointViewModel>(chartPoint_0 => new DataPointViewModel
                {
                    Series = new SeriesViewModel
                    {
                        PointGeometry = (((Series)chartPoint_0.SeriesView).PointGeometry ?? Geometry.Parse("M0,0 L1,0")),
                        Fill = ((!(((Series)chartPoint_0.SeriesView) is IFondeable) || chartPoint_0.SeriesView is IVerticalStackedAreaSeriesView || chartPoint_0.SeriesView is IStackedAreaSeriesView) ? ((Series)chartPoint_0.SeriesView).Fill : ((IFondeable)chartPoint_0.SeriesView).PointForeground),
                        Stroke = ((Series)chartPoint_0.SeriesView).Stroke,
                        StrokeThickness = ((Series)chartPoint_0.SeriesView).StrokeThickness,
                        Title = ((Series)chartPoint_0.SeriesView).Title
                    },
                    ChartPoint = chartPoint_0
                })).ToList();
                chartTooltip2.Data = tooltipData2;
                chart_1.TooltipContainer.IsOpen = true;
                chart_1.DataTooltip.UpdateLayout();
                Point tooltipPosition = chart_1.GetTooltipPosition(chartPoint_1);
                tooltipPosition = new Point(Canvas.GetLeft(chart_1.DrawMargin) + tooltipPosition.X, Canvas.GetTop(chart_1.DrawMargin) + tooltipPosition.Y);
                if (chart_1.DisableAnimations)
                {
                    chart_1.TooltipContainer.VerticalOffset = tooltipPosition.Y;
                    chart_1.TooltipContainer.HorizontalOffset = tooltipPosition.X;
                }
                else
                {
                    chart_1.TooltipContainer.BeginAnimation(Popup.VerticalOffsetProperty, new DoubleAnimation(tooltipPosition.Y, TimeSpan.FromMilliseconds(200.0)));
                    chart_1.TooltipContainer.BeginAnimation(Popup.HorizontalOffsetProperty, new DoubleAnimation(tooltipPosition.X, TimeSpan.FromMilliseconds(200.0)));
                }
            }
            chart_1.OnDataHover(chartPoint_1, chartPoint_1);
        }

        private static void ChartPointLeave(ChartPoint chartPoint_1, Chart chart_1)
        {
            chart_1.TooltipTimeoutTimer.Stop();
            chart_1.TooltipTimeoutTimer.Start();
            if (chartPoint_1 == null)
            {
                return;
            }
            if (chart_1.Hoverable)
            {
                chartPoint_1.View.OnHoverLeave(chartPoint_1);
            }
        }



        private IEnumerable<ChartPoint> method_3(ISeriesView iseriesView_0, IPointEvaluator<T> ipointEvaluator_1, bool bool_1, bool bool_2)
        {
            Class16 @class = new Class16(-2);
            @class.gearedValues_0 = this;
            @class.iseriesView_1 = iseriesView_0;
            @class.ipointEvaluator_1 = ipointEvaluator_1;
            @class.bool_3 = bool_1;
            @class.bool_1 = bool_2;
            return @class;
        }

        public GearedValues()
        {
            this.Trackers = new Dictionary<ISeriesView, PointTracker>();
            base.NoisyCollectionChanged += this.NoisyCollectionChanged;
            this.EvaluatesLimits = true;
            this.Quality = Quality.High;
        }

        public GearedValues(IEnumerable<T> collection) : base(collection)
        {
            this.Trackers = new Dictionary<ISeriesView, PointTracker>();
            base.NoisyCollectionChanged += this.NoisyCollectionChanged;
        }

        private Dictionary<ISeriesView, PointTracker> Trackers { get; set; }


        private IPointEvaluator<T> DefaultConfiguration { get; set; }


        private bool EvaluatesLimits { get; set; }


        public Quality Quality { get; set; }


        private Geometry PointGeometry { get; set; }
        /// <summary>
        /// 所属图表
        /// </summary>
        public Chart Chart => chart_0;

        public void Initialize(ISeriesView seriesView)
        {
            Chart chart = seriesView.Model.Chart.View as Chart;
            chart_0 = chart;

            if (!dictionary_1.ContainsKey(chart))
            {
                chart.MouseMove += this.ChartPointMove;
                chart.MouseDown += this.ChartPointClick;
                dictionary_1[chart] = true;
            }
            if (!this.EvaluatesLimits)
            {
                return;
            }
            IPointEvaluator<T> pointEvaluator = this.method_6(seriesView);
            if (pointEvaluator == null)
            {
                return;
            }
            double num = double.PositiveInfinity;
            double num2 = double.NegativeInfinity;
            double num3 = double.PositiveInfinity;
            double num4 = double.NegativeInfinity;
            double num5 = double.PositiveInfinity;
            double num6 = double.NegativeInfinity;
            PointTracker tracker = this.GetTracker(seriesView);
            ChartPoint chartPoint = new ChartPoint();
            var AxisX = seriesView.Model.Chart.AxisX[seriesView.ScalesXAt];
            var AxisY = seriesView.Model.Chart.AxisY[seriesView.ScalesYAt];
            double num7 = double.IsNaN(AxisX.MinValue) ? double.NegativeInfinity : AxisX.MinValue;
            double num8 = double.IsNaN(AxisX.MaxValue) ? double.PositiveInfinity : AxisX.MaxValue;
            double num9 = double.IsNaN(AxisY.MinValue) ? double.NegativeInfinity : AxisY.MinValue;
            double num10 = double.IsNaN(AxisY.MaxValue) ? double.PositiveInfinity : AxisY.MaxValue;
            bool flag = seriesView.Model.SeriesOrientation == SeriesOrientation.Horizontal;
            int num11 = -1;
            foreach (T value in this)
            {
                num11++;
                pointEvaluator.Evaluate(num11, value, chartPoint);
                if (flag)
                {
                    if (chartPoint.X < num7)
                    {
                        continue;
                    }
                    if (chartPoint.X > num8)
                    {
                        continue;
                    }
                }
                else if (chartPoint.Y < num9 || chartPoint.Y > num10)
                {
                    continue;
                }
                if (seriesView is IFinancialSeriesView)
                {
                    if (chartPoint.X < num)
                    {
                        num = chartPoint.X;
                    }
                    if (chartPoint.X > num2)
                    {
                        num2 = chartPoint.X;
                    }
                    if (chartPoint.Low < num3)
                    {
                        num3 = chartPoint.Low;
                    }
                    if (chartPoint.High > num4)
                    {
                        num4 = chartPoint.High;
                    }
                    if (chartPoint.Weight < num5)
                    {
                        num5 = chartPoint.Weight;
                    }
                    if (chartPoint.Weight > num6)
                    {
                        num6 = chartPoint.Weight;
                    }
                }
                else if (!(seriesView is IScatterSeriesView) && !(seriesView is IHeatSeriesView))
                {
                    if (chartPoint.X < num)
                    {
                        num = chartPoint.X;
                    }
                    if (chartPoint.X > num2)
                    {
                        num2 = chartPoint.X;
                    }
                    if (chartPoint.Y < num3)
                    {
                        num3 = chartPoint.Y;
                    }
                    if (chartPoint.Y > num4)
                    {
                        num4 = chartPoint.Y;
                    }
                }
                else
                {
                    if (chartPoint.X < num)
                    {
                        num = chartPoint.X;
                    }
                    if (chartPoint.X > num2)
                    {
                        num2 = chartPoint.X;
                    }
                    if (chartPoint.Y < num3)
                    {
                        num3 = chartPoint.Y;
                    }
                    if (chartPoint.Y > num4)
                    {
                        num4 = chartPoint.Y;
                    }
                    if (chartPoint.Weight < num5)
                    {
                        num5 = chartPoint.Weight;
                    }
                    if (chartPoint.Weight > num6)
                    {
                        num6 = chartPoint.Weight;
                    }
                }
            }
            tracker.XLimit = new CoreLimit(double.IsInfinity(num) ? 0.0 : num, double.IsInfinity(num3) ? 1.0 : num2);
            tracker.YLimit = new CoreLimit(double.IsInfinity(num3) ? 0.0 : num3, double.IsInfinity(num4) ? 1.0 : num4);
            tracker.WLimit = new CoreLimit(double.IsInfinity(num5) ? 0.0 : num5, double.IsInfinity(num6) ? 1.0 : num6);
        }

        public IEnumerable<ChartPoint> GetPoints(ISeriesView series)
        {
            return this.GetSeriesPoints(series).ToArray();
        }

        public void InitializeStep(ISeriesView series)
        {
            this.InitializeStepCheck(series);

            PointTracker tracker = this.GetTracker(series);
            int gci = tracker.Gci;
            tracker.Gci = gci + 1;
        }

        public void CollectGarbage(ISeriesView seriesView)
        {

            bool isClass = typeof(T).IsClass;
            PointTracker tracker = this.GetTracker(seriesView);
            var cps = tracker.Indexed.Values.Where(zz => zz.Gci < tracker.Gci || double.IsNaN(zz.X) || double.IsNaN(zz.Y))
                .Concat(tracker.Referenced.Values.Where(zz => zz.Gci < tracker.Gci || double.IsNaN(zz.X) || double.IsNaN(zz.Y))).ToArray();
            foreach (ChartPoint chartPoint in cps)
            {
                if (chartPoint.View != null)
                {
                    chartPoint.View.RemoveFromView(seriesView.Model.Chart);
                }
                if (!isClass)
                {
                    tracker.Indexed.Remove(chartPoint.Key);
                }
                else
                {
                    tracker.Referenced.Remove(chartPoint.Instance);
                }
            }
        }

        public PointTracker GetTracker(ISeriesView view)
        {
            PointTracker pointTracker;
            if (this.Trackers.TryGetValue(view, out pointTracker))
            {
                return pointTracker;
            }
            pointTracker = new PointTracker();
            this.Trackers[view] = pointTracker;
            return pointTracker;
        }

        public void SetLimits(ISeriesView view, double xMin, double xMax, double yMin, double yMax, double wMin = 0.0, double wMax = 0.0)
        {
            PointTracker tracker = this.GetTracker(view);
            tracker.XLimit = new CoreLimit(xMin, xMax);
            tracker.YLimit = new CoreLimit(yMin, yMax);
            tracker.WLimit = new CoreLimit(wMin, wMax);
            this.EvaluatesLimits = false;
        }

        public void RemoveLimits()
        {
            this.EvaluatesLimits = true;
        }

        public void Dispose()
        {
            this.Trackers = null;
            if (chart_0 != null)
            {
                dictionary_1.Remove(chart_0);
            }
            chart_0 = null;
        }

        private IEnumerable<ChartPoint> GetSeriesPoints(ISeriesView iseriesView_0)
        {
            if (iseriesView_0 == null)
            {
                return Enumerable.Empty<ChartPoint>();
            }
            if (iseriesView_0.Model != null && iseriesView_0.Model.Chart != null && iseriesView_0.Model.Chart.AxisX != null && iseriesView_0.Model.Chart.AxisY != null)
            {
                if (!iseriesView_0.Model.Chart.AxisX.Any(new Func<AxisCore, bool>(ac => ac == null)))
                {
                    goto IL_8B;
                }
            }
            if (!DesignerProperties.GetIsInDesignMode((Series)iseriesView_0))
            {
                return Enumerable.Empty<ChartPoint>();
            }
        IL_8B:
            IPointEvaluator<T> ipointEvaluator_ = this.method_6(iseriesView_0);
            bool isClass;
            bool bool_ = (isClass = typeof(T).IsClass) && typeof(IObservableChartPoint).IsAssignableFrom(typeof(T));
            bool bool_2 = isClass && typeof(INotifyPropertyChanged).IsAssignableFrom(typeof(T));
            return this.method_5(iseriesView_0, ipointEvaluator_, isClass, bool_, bool_2);
        }

        private IEnumerable<ChartPoint> method_5(ISeriesView iseriesView_0, IPointEvaluator<T> ipointEvaluator_1, bool bool_1, bool bool_2, bool bool_3)
        {
            Type type = iseriesView_0.Model.GetType();
            if (DesignerProperties.GetIsInDesignMode((Series)iseriesView_0))
            {
                Random random = new Random();
                return new ChartPoint[]
                {
                    new ChartPoint
                    {
                        X = 0.0,
                        Y = (double)random.Next(0, 100)
                    },
                    new ChartPoint
                    {
                        X = 1.0,
                        Y = (double)random.Next(0, 100)
                    },
                    new ChartPoint
                    {
                        X = 2.0,
                        Y = (double)random.Next(0, 100)
                    },
                    new ChartPoint
                    {
                        X = 3.0,
                        Y = (double)random.Next(0, 100)
                    },
                    new ChartPoint
                    {
                        X = 4.0,
                        Y = (double)random.Next(0, 100)
                    }
                };
            }
            if (type == typeof(LineAlgorithm) || type == typeof(StackedAreaAlgorithm) || type == typeof(StepLineAlgorithm))
            {
                return this.method_14(iseriesView_0, ipointEvaluator_1, bool_1, bool_2, bool_3);
            }
            if (type == typeof(VerticalLineAlgorithm) || type == typeof(VerticalStackedAreaAlgorithm))
            {
                VerticalAlgorithm va = new VerticalAlgorithm(-2);
                va.gearedValues_0 = this;
                va.iseriesView_1 = iseriesView_0;
                va.ipointEvaluator_1 = ipointEvaluator_1;
                va.bool_5 = bool_1;
                va.bool_1 = bool_2;
                va.bool_3 = bool_3;
                return va;
            }
            if (type == typeof(ScatterAlgorithm))
            {

                return new ScattAlgorithm(-2)
                {
                    gearedValues_0 = this,
                    iseriesView_1 = iseriesView_0,
                    ipointEvaluator_1 = ipointEvaluator_1,
                    bool_6 = bool_1,
                    bool_1 = bool_2,
                    bool_3 = bool_3
                };
            }
            if (!(type == typeof(ColumnAlgorithm)) && !(type == typeof(StackedColumnAlgorithm)) && !(type == typeof(OhlcAlgorithm)) && !(type == typeof(CandleAlgorithm)))
            {
                return this.method_3(iseriesView_0, ipointEvaluator_1, bool_1, bool_2);
            }
            return new DefaultAlgorithm(-2)
            {
                gearedValues_0 = this,
                iseriesView_1 = iseriesView_0,
                ipointEvaluator_1 = ipointEvaluator_1,
                bool_5 = bool_1,
                bool_1 = bool_2,
                bool_3 = bool_3
            };
        }

        private IPointEvaluator<T> method_6(ISeriesView iseriesView_0)
        {
            if (iseriesView_0 == null)
            {
                return null;
            }
            if (iseriesView_0.Model.SeriesCollection == null)
            {
                return null;
            }
            IPointEvaluator<T> pointEvaluator = (iseriesView_0.Configuration ?? iseriesView_0.Model.SeriesCollection.Configuration) as IPointEvaluator<T>;
            if (pointEvaluator != null)
            {
                return pointEvaluator;
            }
            IPointEvaluator<T> result;
            if ((result = this.DefaultConfiguration) == null)
            {
                result = (this.DefaultConfiguration = (ChartCore.Configurations.GetConfig<T>(iseriesView_0.Model.SeriesOrientation) as IPointEvaluator<T>));
            }
            return result;
        }

        private static ChartPoint smethod_3(bool bool_1, PointTracker pointTracker_0, int int_0, T gparam_0)
        {
            ChartPoint chartPoint;
            if (!bool_1)
            {
                if (pointTracker_0.Indexed.TryGetValue(int_0, out chartPoint))
                {
                    return chartPoint;
                }
                chartPoint = new ChartPoint
                {
                    Instance = gparam_0,
                    Key = int_0
                };
                pointTracker_0.Indexed[int_0] = chartPoint;
            }
            else
            {
                if (pointTracker_0.Referenced.TryGetValue(gparam_0, out chartPoint))
                {
                    return chartPoint;
                }
                chartPoint = new ChartPoint
                {
                    Instance = gparam_0,
                    Key = int_0
                };
                pointTracker_0.Referenced[gparam_0] = chartPoint;
            }
            return chartPoint;
        }

        private void method_7()
        {
            this.Trackers.Keys.ForEach(zz => zz.Model.Chart.Updater.Run(false, false));
        }

        private void UpdateAllSeriess(object sender, PropertyChangedEventArgs e)
        {
            this.Trackers.Keys.ForEach(zz => zz.Model.Chart.Updater.Run(false, false));
        }



        private void InitializeStepCheck(ISeriesView iseriesView_0)
        {
            PointTracker tracker = this.GetTracker(iseriesView_0);
            if (tracker.Gci != int.MaxValue)
            {
                return;
            }
            tracker.Gci = 0;
            foreach (ChartPoint chartPoint in tracker.Indexed.Values.Concat(tracker.Referenced.Values))
            {
                chartPoint.Gci = 0.0;
            }
        }



        private void NoisyCollectionChanged(IEnumerable<T> ienumerable_0, IEnumerable<T> ienumerable_1)
        {
            if (this.Trackers.Keys.All(zz => zz != null && zz.Model.Chart != null))
            {
                this.Trackers.Keys.ForEach(zz => zz.Model.Chart.Updater.Run(false, false));
            }
        }





        private IEnumerable<ChartPoint> method_14(ISeriesView iseriesView_0, IPointEvaluator<T> ipointEvaluator_1, bool bool_1, bool bool_2, bool bool_3)
        {
            GearedValues<T>.Class22 @class = new GearedValues<T>.Class22(-2);
            @class.gearedValues_0 = this;
            @class.iseriesView_1 = iseriesView_0;
            @class.ipointEvaluator_1 = ipointEvaluator_1;
            @class.bool_5 = bool_1;
            @class.bool_1 = bool_2;
            @class.bool_3 = bool_3;
            return @class;
        }

        private ChartPoint chartPoint_0;

        private DateTime dateTime_0 = DateTime.MinValue;


        private static readonly Dictionary<Chart, bool> dictionary_1 = new Dictionary<Chart, bool>();

        private static Chart chart_0;





        [CompilerGenerated]
        private sealed class Class19
        {
            internal double method_0(double double_3)
            {
                return this.double_0 * (double_3 - this.double_1) + this.double_2;
            }

            public double double_0;

            public double double_1;

            public double double_2;
        }

        [CompilerGenerated]
        private sealed class Class21
        {
            internal double method_0(double double_3)
            {
                return this.double_0 * (double_3 - this.double_1) + this.double_2;
            }

            public double double_0;

            public double double_1;

            public double double_2;
        }
        [CompilerGenerated]
        private sealed class DefaultAlgorithm : IEnumerable<ChartPoint>, IEnumerator<ChartPoint>, IEnumerable, IDisposable, IEnumerator
        {
            private int int_0;

            private ChartPoint chartPoint_0;

            private int currentManagedThreadId;

            private ISeriesView iseriesView_0;

            public ISeriesView iseriesView_1;

            public GearedValues<T> gearedValues_0;

            private int int_2;

            private bool bool_0;

            public bool bool_1;

            private bool bool_2;

            public bool bool_3;

            private IPointEvaluator<T> ipointEvaluator_0;

            public IPointEvaluator<T> ipointEvaluator_1;

            private ChartPoint chartPoint_1;

            private double double_0;

            private double double_1;

            private bool bool_4;

            public bool bool_5;

            private PointTracker pointTracker_0;

            private int int_3;

            private IEnumerator<T> ienumerator_0;

            ChartPoint IEnumerator<ChartPoint>.Current => chartPoint_0;
            object IEnumerator.Current => chartPoint_0;


            [DebuggerHidden]
            public DefaultAlgorithm(int int_4)
            {
                int_0 = int_4;
                currentManagedThreadId = Environment.CurrentManagedThreadId;
            }

            [DebuggerHidden]
            void IDisposable.Dispose()
            {
                int num = int_0;
                if (num == -3 || num == 1)
                {
                    try
                    {
                    }
                    finally
                    {
                        Dispose();
                    }
                }
            }

            bool IEnumerator.MoveNext()
            {

                try
                {
                    int num = int_0;
                    GearedValues<T> gearedValues = gearedValues_0;
                    switch (num)
                    {
                        default:
                            return false;
                        case 1:
                            int_0 = -3;
                            break;
                        case 0:
                            {
                                int_0 = -1;
                                if (iseriesView_0 == null)
                                {
                                    return false;
                                }
                                pointTracker_0 = gearedValues.GetTracker(iseriesView_0);
                                int_3 = pointTracker_0.Gci;
                                AxisCore val = iseriesView_0.Model.Chart.AxisX[iseriesView_0.ScalesXAt];
                                double_0 = (double.IsNaN(val.MinValue - val.S) ? double.MinValue : (val.MinValue - val.S));
                                double_1 = (double.IsNaN(val.MaxValue + val.S) ? double.MaxValue : (val.MaxValue + val.S));
                                chartPoint_1 = new ChartPoint();
                                int_2 = -1;
                                ienumerator_0 = ((NoisyCollection<T>)gearedValues).GetEnumerator();
                                int_0 = -3;
                                break;
                            }
                    }
                    T current;
                    do
                    {
                        if (ienumerator_0.MoveNext())
                        {
                            current = ienumerator_0.Current;
                            int_2++;
                            if (bool_0)
                            {
                                IObservableChartPoint val2 = (IObservableChartPoint)(object)current;
                                if (val2 != null)
                                {
                                    val2.PointChanged -= gearedValues.method_7;
                                    val2.PointChanged += gearedValues.method_7;
                                }
                            }
                            if (bool_2)
                            {
                                INotifyPropertyChanged notifyPropertyChanged = (INotifyPropertyChanged)(object)current;
                                if (notifyPropertyChanged != null)
                                {
                                    notifyPropertyChanged.PropertyChanged -= gearedValues.UpdateAllSeriess;
                                    notifyPropertyChanged.PropertyChanged += gearedValues.UpdateAllSeriess;
                                }
                            }
                            ipointEvaluator_0.Evaluate(int_2, current, chartPoint_1);
                            continue;
                        }
                        Dispose();
                        ienumerator_0 = null;
                        return false;
                    }
                    while (chartPoint_1.X < double_0 || !(chartPoint_1.X <= double_1));
                    ChartPoint val3 = GearedValues<T>.smethod_3(bool_4, pointTracker_0, int_2, current);
                    val3.Gci = int_3;
                    val3.Instance = current;
                    val3.Key = int_2;
                    val3.SeriesView = iseriesView_0;
                    ipointEvaluator_0.Evaluate(int_2, current, val3);
                    chartPoint_0 = val3;
                    int_0 = 1;
                    return true;
                }
                catch
                {
                    //try-fault
                    ((IDisposable)this).Dispose();
                    throw;
                }
            }

            private void Dispose()
            {
                int_0 = -1;
                if (ienumerator_0 != null)
                {
                    ienumerator_0.Dispose();
                }
            }

            [DebuggerHidden]
            void IEnumerator.Reset()
            {
                throw new NotSupportedException();
            }

            [DebuggerHidden]
            IEnumerator<ChartPoint> IEnumerable<ChartPoint>.GetEnumerator()
            {
                DefaultAlgorithm @class;
                if (int_0 == -2 && currentManagedThreadId == Environment.CurrentManagedThreadId)
                {
                    int_0 = 0;
                    @class = this;
                }
                else
                {
                    @class = new DefaultAlgorithm(0)
                    {
                        gearedValues_0 = gearedValues_0
                    };
                }
                @class.iseriesView_0 = iseriesView_1;
                @class.ipointEvaluator_0 = ipointEvaluator_1;
                @class.bool_4 = bool_5;
                @class.bool_0 = bool_1;
                @class.bool_2 = bool_3;
                return @class;
            }

            [DebuggerHidden]
            IEnumerator IEnumerable.GetEnumerator()
            {
                return ((IEnumerable<ChartPoint>)this).GetEnumerator();
            }
        }

        [CompilerGenerated]
        private sealed class Class16 : IEnumerable<ChartPoint>, IEnumerator<ChartPoint>, IEnumerable, IDisposable, IEnumerator
        {
            private int int_0;

            private ChartPoint chartPoint_0;

            private int currentManagedThreadId;

            private ISeriesView iseriesView_0;

            public ISeriesView iseriesView_1;

            public GearedValues<T> gearedValues_0;

            private int int_2;

            private bool bool_0;

            public bool bool_1;

            private IPointEvaluator<T> ipointEvaluator_0;

            public IPointEvaluator<T> ipointEvaluator_1;

            private ChartPoint chartPoint_1;

            private double double_0;

            private double double_1;

            private bool bool_2;

            public bool bool_3;

            private PointTracker pointTracker_0;

            private int int_3;

            private IEnumerator<T> ienumerator_0;

            ChartPoint IEnumerator<ChartPoint>.Current => chartPoint_0;


            object IEnumerator.Current => chartPoint_0;


            [DebuggerHidden]
            public Class16(int int_4)
            {
                int_0 = int_4;
                currentManagedThreadId = Environment.CurrentManagedThreadId;
            }

            [DebuggerHidden]
            void IDisposable.Dispose()
            {
                int num = int_0;
                if (num == -3 || num == 1)
                {
                    Dispose();

                }
            }

            bool IEnumerator.MoveNext()
            {
                try
                {
                    int num = int_0;
                    GearedValues<T> gearedValues = gearedValues_0;
                    switch (num)
                    {
                        default:
                            return false;
                        case 1:
                            int_0 = -3;
                            break;
                        case 0:
                            {
                                int_0 = -1;
                                if (iseriesView_0 == null)
                                {
                                    return false;
                                }
                                pointTracker_0 = gearedValues.GetTracker(iseriesView_0);
                                int_3 = pointTracker_0.Gci;
                                AxisCore val = iseriesView_0.Model.Chart.AxisY[iseriesView_0.ScalesYAt];
                                double_0 = (double.IsNaN(val.MinValue - val.S) ? double.MinValue : (val.MinValue - val.S));
                                double_1 = (double.IsNaN(val.MaxValue + val.S) ? double.MaxValue : (val.MaxValue + val.S));
                                chartPoint_1 = new ChartPoint();
                                int_2 = -1;
                                ienumerator_0 = (gearedValues).GetEnumerator();
                                int_0 = -3;
                                break;
                            }
                    }
                    T current;
                    do
                    {
                        if (ienumerator_0.MoveNext())
                        {
                            current = ienumerator_0.Current;
                            int_2++;
                            if (bool_0)
                            {
                                IObservableChartPoint val2 = (IObservableChartPoint)current;
                                if (val2 != null)
                                {
                                    val2.PointChanged -= gearedValues.method_7;
                                    val2.PointChanged += gearedValues.method_7;
                                }
                            }
                            ipointEvaluator_0.Evaluate(int_2, current, chartPoint_1);
                            continue;
                        }
                        Dispose();
                        ienumerator_0 = null;
                        return false;
                    }
                    while (chartPoint_1.Y < double_0 || !(chartPoint_1.Y <= double_1));
                    ChartPoint val3 = smethod_3(bool_2, pointTracker_0, int_2, current);
                    val3.Gci = int_3;
                    val3.Instance = current;
                    val3.Key = int_2;
                    val3.SeriesView = iseriesView_0;
                    ipointEvaluator_0.Evaluate(int_2, current, val3);
                    chartPoint_0 = val3;
                    int_0 = 1;
                    return true;
                }
                catch
                {
                    ((IDisposable)this).Dispose();
                    throw;
                }
            }

            private void Dispose()
            {
                int_0 = -1;
                if (ienumerator_0 != null)
                {
                    ienumerator_0.Dispose();
                }
            }

            [DebuggerHidden]
            void IEnumerator.Reset()
            {
                throw new NotSupportedException();
            }

            [DebuggerHidden]
            IEnumerator<ChartPoint> IEnumerable<ChartPoint>.GetEnumerator()
            {
                Class16 @class;
                if (int_0 == -2 && currentManagedThreadId == Environment.CurrentManagedThreadId)
                {
                    int_0 = 0;
                    @class = this;
                }
                else
                {
                    @class = new Class16(0)
                    {
                        gearedValues_0 = gearedValues_0
                    };
                }
                @class.iseriesView_0 = iseriesView_1;
                @class.ipointEvaluator_0 = ipointEvaluator_1;
                @class.bool_2 = bool_3;
                @class.bool_0 = bool_1;
                return @class;
            }

            [DebuggerHidden]
            IEnumerator IEnumerable.GetEnumerator()
            {
                return ((IEnumerable<ChartPoint>)this).GetEnumerator();
            }
        }

        [CompilerGenerated]
        private sealed class ScattAlgorithm : IEnumerable<ChartPoint>, IEnumerator<ChartPoint>, IEnumerable, IDisposable, IEnumerator
        {
            private int int_0;

            private ChartPoint chartPoint_0;

            private int int_1;

            private ISeriesView iseriesView_0;

            public ISeriesView iseriesView_1;

            public GearedValues<T> gearedValues_0;

            private double double_0;

            private List<T> list_0;

            private bool bool_0;

            public bool bool_1;

            private bool bool_2;

            public bool bool_3;

            private IPointEvaluator<T> ipointEvaluator_0;

            public IPointEvaluator<T> ipointEvaluator_1;

            private ChartPoint chartPoint_1;

            private double double_1;

            private double double_2;

            private double double_3;

            private double double_4;

            private AxisCore axisCore_0;

            private int int_2;

            private AxisCore axisCore_1;

            private int int_3;

            private bool[,] bool_4;

            private bool bool_5;

            public bool bool_6;

            private PointTracker pointTracker_0;

            private int int_4;

            private int int_5;

            ChartPoint IEnumerator<ChartPoint>.Current
            {
                [DebuggerHidden]
                get
                {
                    return chartPoint_0;
                }
            }

            object IEnumerator.Current
            {
                [DebuggerHidden]
                get
                {
                    return chartPoint_0;
                }
            }

            [DebuggerHidden]
            public ScattAlgorithm(int int_6)
            {
                int_0 = int_6;
                int_1 = Environment.CurrentManagedThreadId;
            }

            [DebuggerHidden]
            void IDisposable.Dispose()
            {
            }

            bool IEnumerator.MoveNext()
            {

                int num = int_0;
                GearedValues<T> gearedValues = gearedValues_0;
                if (num != 0)
                {
                    if (num != 1)
                    {
                        return false;
                    }
                    int_0 = -1;
                    goto IL_0527;
                }
                int_0 = -1;
                if (iseriesView_0 == null)
                {
                    return false;
                }
                switch (gearedValues.Quality)
                {
                    default:
                        throw new ArgumentOutOfRangeException();
                    case Quality.Low:
                        double_0 = 10.0;
                        break;
                    case Quality.Medium:
                        double_0 = 5.0;
                        break;
                    case Quality.High:
                        double_0 = 2.0;
                        break;
                    case Quality.Highest:
                        double_0 = 1.0;
                        break;
                }
                pointTracker_0 = gearedValues.GetTracker(iseriesView_0);
                int_4 = pointTracker_0.Gci;
                list_0 = ((IEnumerable<T>)gearedValues).ToList();
                axisCore_0 = iseriesView_0.Model.Chart.AxisX[iseriesView_0.ScalesXAt];
                axisCore_1 = iseriesView_0.Model.Chart.AxisY[iseriesView_0.ScalesYAt];
                double_1 = (double.IsNaN(axisCore_0.MinValue - axisCore_0.S) ? double.MinValue : (axisCore_0.MinValue - axisCore_0.S));
                double_2 = (double.IsNaN(axisCore_0.MaxValue + axisCore_0.S) ? double.MaxValue : (axisCore_0.MaxValue + axisCore_0.S));
                double_3 = (double.IsNaN(axisCore_1.MinValue - axisCore_1.S) ? double.MinValue : (axisCore_1.MinValue - axisCore_1.S));
                double_4 = (double.IsNaN(axisCore_1.MaxValue + axisCore_1.S) ? double.MaxValue : (axisCore_1.MaxValue + axisCore_1.S));
                Chart val = (Chart)iseriesView_0.Model.Chart.View;
                Point point = LiveCharts.Wpf.Extentions.ConvertToChartValues(val, new Point(double_0, double_0), 0, 0);
                Point point2 = LiveCharts.Wpf.Extentions.ConvertToChartValues(val, new Point(0.0, 0.0), 0, 0);
                point = new Point(point.X - point2.X, point2.Y - point.Y);
                int_2 = (int)((axisCore_0.S * 2.0 + axisCore_0.TopLimit - axisCore_0.BotLimit) / point.X);
                int_3 = (int)((axisCore_1.S * 2.0 + axisCore_1.TopLimit - axisCore_1.BotLimit) / point.Y);
                bool_4 = new bool[int_2 + 1, int_3 + 1];
                chartPoint_1 = new ChartPoint();
                int_5 = 0;
                goto IL_0539;
            IL_0527:
                int_5++;
                goto IL_0539;
            IL_0539:
                if (int_5 < ((NoisyCollection<T>)gearedValues).Count)
                {
                    T val2 = list_0[int_5];
                    if (bool_0)
                    {
                        IObservableChartPoint val3 = (IObservableChartPoint)(object)val2;
                        if (val3 != null)
                        {
                            val3.PointChanged -= gearedValues.method_7;
                            val3.PointChanged += gearedValues.method_7;
                        }
                    }
                    if (bool_2)
                    {
                        INotifyPropertyChanged notifyPropertyChanged = (INotifyPropertyChanged)(object)val2;
                        if (notifyPropertyChanged != null)
                        {
                            notifyPropertyChanged.PropertyChanged -= gearedValues.UpdateAllSeriess;
                            notifyPropertyChanged.PropertyChanged += gearedValues.UpdateAllSeriess;
                        }
                    }
                    ipointEvaluator_0.Evaluate(int_5, val2, chartPoint_1);
                    if (!(chartPoint_1.X < double_1) && !(chartPoint_1.X > double_2) && !(chartPoint_1.Y < double_3) && !(chartPoint_1.Y > double_4))
                    {
                        int num2 = (int)((chartPoint_1.X - (axisCore_0.BotLimit - axisCore_0.S)) / (axisCore_0.S * 2.0 + axisCore_0.TopLimit - axisCore_0.BotLimit) * (double)int_2);
                        int num3 = (int)((chartPoint_1.Y - (axisCore_1.BotLimit - axisCore_1.S)) / (axisCore_1.S * 2.0 + axisCore_1.TopLimit - axisCore_1.BotLimit) * (double)int_3);
                        if (!bool_4[num2, num3])
                        {
                            bool_4[num2, num3] = true;
                            ChartPoint val4 = GearedValues<T>.smethod_3(bool_5, pointTracker_0, int_5, val2);
                            val4.Gci = int_4;
                            val4.Instance = val2;
                            val4.Key = int_5;
                            val4.SeriesView = iseriesView_0;
                            ipointEvaluator_0.Evaluate(int_5, val2, val4);
                            chartPoint_0 = val4;
                            int_0 = 1;
                            return true;
                        }
                    }
                    goto IL_0527;
                }
                return false;
            }

            [DebuggerHidden]
            void IEnumerator.Reset()
            {
                throw new NotSupportedException();
            }

            [DebuggerHidden]
            IEnumerator<ChartPoint> IEnumerable<ChartPoint>.GetEnumerator()
            {
                ScattAlgorithm @class;
                if (int_0 == -2 && int_1 == Environment.CurrentManagedThreadId)
                {
                    int_0 = 0;
                    @class = this;
                }
                else
                {
                    @class = new ScattAlgorithm(0)
                    {
                        gearedValues_0 = gearedValues_0
                    };
                }
                @class.iseriesView_0 = iseriesView_1;
                @class.ipointEvaluator_0 = ipointEvaluator_1;
                @class.bool_5 = bool_6;
                @class.bool_0 = bool_1;
                @class.bool_2 = bool_3;
                return @class;
            }

            [DebuggerHidden]
            IEnumerator IEnumerable.GetEnumerator()
            {
                return ((IEnumerable<ChartPoint>)this).GetEnumerator();
            }
        }
        [CompilerGenerated]
        private sealed class VerticalAlgorithm : IEnumerable<ChartPoint>, IEnumerator<ChartPoint>, IEnumerable, IDisposable, IEnumerator
        {
            private int int_0;

            private ChartPoint chartPoint_0;

            private int currentManagedThreadId;

            public GearedValues<T> gearedValues_0;

            private ISeriesView iseriesView_0;

            public ISeriesView iseriesView_1;

            private int int_2;

            private bool bool_0;

            public bool bool_1;

            private bool bool_2;

            public bool bool_3;

            private IPointEvaluator<T> ipointEvaluator_0;

            public IPointEvaluator<T> ipointEvaluator_1;

            private ChartPoint chartPoint_1;

            private Func<double, double> func_0;

            private double double_0;

            private double double_1;

            private double double_2;

            private bool bool_4;

            public bool bool_5;

            private PointTracker pointTracker_0;

            private int int_3;

            private int int_4;

            private double double_3;

            private double double_4;

            private double double_5;

            private int int_5;

            private T gparam_0;

            private Class1<T>[] class1_0;

            private int int_6;

            private Class1<T> class1_1;

            private bool bool_6;

            private IEnumerator<T> ienumerator_0;

            private Class1<T>[] class1_2;

            private int int_7;

            ChartPoint IEnumerator<ChartPoint>.Current => chartPoint_0;


            object IEnumerator.Current => chartPoint_0;


            [DebuggerHidden]
            public VerticalAlgorithm(int int_8)
            {
                int_0 = int_8;
                currentManagedThreadId = Environment.CurrentManagedThreadId;
            }

            [DebuggerHidden]
            void IDisposable.Dispose()
            {
                int num = int_0;
                if (num == -3 || (uint)(num - 1) <= 3u)
                {
                    try
                    {
                    }
                    finally
                    {
                        method_0();
                    }
                }
            }

            bool IEnumerator.MoveNext()
            {
                //IL_01e4: Unknown result type (might be due to invalid IL or missing references)
                //IL_01ee: Expected O, but got Unknown
                //IL_0393: Unknown result type (might be due to invalid IL or missing references)
                //IL_039a: Expected O, but got Unknown
                //IL_0888: Unknown result type (might be due to invalid IL or missing references)
                //IL_088f: Expected O, but got Unknown
                //IL_08af: Unknown result type (might be due to invalid IL or missing references)
                //IL_08c7: Unknown result type (might be due to invalid IL or missing references)
                //IL_08f8: Unknown result type (might be due to invalid IL or missing references)
                try
                {
                    int num = int_0;
                    GearedValues<T> gearedValues = gearedValues_0;
                    ChartPoint val5;
                    switch (num)
                    {
                        default:
                            return false;
                        case 0:
                            {
                                int_0 = -1;
                                Class19 CS_0024_003C_003E8__locals0 = new Class19();
                                switch (gearedValues.Quality)
                                {
                                    default:
                                        throw new ArgumentOutOfRangeException();
                                    case Quality.Low:
                                        double_5 = 10.0;
                                        break;
                                    case Quality.Medium:
                                        double_5 = 5.0;
                                        break;
                                    case Quality.High:
                                        double_5 = 2.0;
                                        break;
                                    case Quality.Highest:
                                        double_5 = 1.0;
                                        break;
                                }
                                int_4 = 0;
                                double_0 = 0.0;
                                class1_0 = new Class1<T>[2]
                                {
                        new Class1<T>
                        {
                            X = double.PositiveInfinity
                        },
                        new Class1<T>
                        {
                            X = double.NegativeInfinity
                        }
                                };
                                pointTracker_0 = gearedValues.GetTracker(iseriesView_0);
                                int_5 = 0;
                                AxisCore val = iseriesView_0.Model.Chart.AxisY[iseriesView_0.ScalesYAt];
                                CS_0024_003C_003E8__locals0.double_1 = val.TopLimit;
                                CS_0024_003C_003E8__locals0.double_2 = iseriesView_0.Model.Chart.DrawMargin.Height + iseriesView_0.Model.Chart.DrawMargin.Top;
                                double botLimit = val.BotLimit;
                                double top = iseriesView_0.Model.Chart.DrawMargin.Top;
                                double num2 = botLimit - CS_0024_003C_003E8__locals0.double_1;
                                CS_0024_003C_003E8__locals0.double_0 = (top - CS_0024_003C_003E8__locals0.double_2) / ((num2 == 0.0) ? double.MinValue : num2);
                                func_0 = (double double_3) => CS_0024_003C_003E8__locals0.double_0 * (double_3 - CS_0024_003C_003E8__locals0.double_1) + CS_0024_003C_003E8__locals0.double_2;
                                chartPoint_1 = new ChartPoint();
                                int_6 = -1;
                                double_1 = (double.IsNaN(val.MinValue - val.S) ? double.MinValue : (val.MinValue - val.S));
                                double_2 = (double.IsNaN(val.MaxValue + val.S) ? double.MaxValue : (val.MaxValue + val.S));
                                bool_6 = false;
                                int_3 = 0;
                                int_2 = -1;
                                ienumerator_0 = ((NoisyCollection<T>)gearedValues).GetEnumerator();
                                int_0 = -3;
                                goto IL_0865;
                            }
                        case 1:
                            int_0 = -3;
                            int_6 = int_4;
                            double_0 = double_3;
                            int_4++;
                            goto IL_0865;
                        case 2:
                            int_0 = -3;
                            double_0 = double_3;
                            int_6 = int_4;
                            class1_0 = new Class1<T>[2]
                            {
                        new Class1<T>
                        {
                            X = double.PositiveInfinity
                        },
                        new Class1<T>
                        {
                            X = double.NegativeInfinity
                        }
                            };
                            goto IL_06ba;
                        case 3:
                            int_0 = -3;
                            goto IL_05d7;
                        case 4:
                            {
                                int_0 = -3;
                                goto IL_033a;
                            }
                        IL_033a:
                            int_4++;
                            gparam_0 = default(T);
                            goto IL_0865;
                        IL_06ba:
                            int_5 = 0;
                            goto IL_06c1;
                        IL_0865:
                            while (true)
                            {
                                if (ienumerator_0.MoveNext())
                                {
                                    gparam_0 = ienumerator_0.Current;
                                    int_2++;
                                    if (bool_0)
                                    {
                                        IObservableChartPoint val2 = (IObservableChartPoint)(object)gparam_0;
                                        if (val2 != null)
                                        {
                                            val2.PointChanged -= gearedValues.method_7;
                                            val2.PointChanged += gearedValues.method_7;
                                        }
                                    }
                                    if (bool_2)
                                    {
                                        INotifyPropertyChanged notifyPropertyChanged = (INotifyPropertyChanged)(object)gparam_0;
                                        if (notifyPropertyChanged != null)
                                        {
                                            notifyPropertyChanged.PropertyChanged -= gearedValues.UpdateAllSeriess;
                                            notifyPropertyChanged.PropertyChanged += gearedValues.UpdateAllSeriess;
                                        }
                                    }
                                    ipointEvaluator_0.Evaluate(int_4, gparam_0, chartPoint_1);
                                    double_3 = func_0(chartPoint_1.Y);
                                    double_4 = Math.Abs(double_0 - double_3);
                                    if (!(chartPoint_1.Y < double_1) && !(chartPoint_1.Y > double_2))
                                    {
                                        break;
                                    }
                                    int_4++;
                                    continue;
                                }
                                method_0();
                                ienumerator_0 = null;
                                Series val3 = (Series)iseriesView_0;
                                if (!bool_6 && int_3 <= 100)
                                {
                                    if (gearedValues.PointGeometry != null)
                                    {
                                        ((Series)iseriesView_0).PointGeometry = gearedValues.PointGeometry;
                                    }
                                }
                                else
                                {
                                    Geometry pointGeometry = ((Series)iseriesView_0).PointGeometry;
                                    if (pointGeometry != null)
                                    {
                                        gearedValues.PointGeometry = pointGeometry;
                                    }
                                    val3.PointGeometry = null;
                                }
                                val3.Model.Chart.View.LoadLegend();
                                return false;
                            }
                            if (int_2 != 0)
                            {
                                if (double_4 > double_5 || int_2 == ((NoisyCollection<T>)gearedValues).Count - 1)
                                {
                                    int num3 = int_5;
                                    if ((uint)num3 > 1u)
                                    {
                                        Class1<T>[] array = class1_0.OrderBy((Class1<T> class1_0) => class1_0.Y).ToArray();
                                        class1_2 = array;
                                        int_7 = 0;
                                        goto IL_05fd;
                                    }
                                    ChartPoint val4 = GearedValues<T>.smethod_3(bool_4, pointTracker_0, int_4, gparam_0);
                                    val4.Gci = pointTracker_0.Gci;
                                    val4.Instance = gparam_0;
                                    val4.Key = int_4;
                                    val4.SeriesView = iseriesView_0;
                                    ipointEvaluator_0.Evaluate(int_4, gparam_0, val4);
                                    int_3++;
                                    chartPoint_0 = val4;
                                    int_0 = 2;
                                    return true;
                                }
                                goto IL_06c1;
                            }
                            val5 = GearedValues<T>.smethod_3(bool_4, pointTracker_0, int_4, gparam_0);
                            val5.Gci = pointTracker_0.Gci;
                            val5.Instance = gparam_0;
                            val5.Key = int_4;
                            val5.SeriesView = iseriesView_0;
                            ipointEvaluator_0.Evaluate(int_4, gparam_0, val5);
                            int_3++;
                            chartPoint_0 = val5;
                            int_0 = 1;
                            return true;
                        IL_05d7:
                            int_6 = class1_1.Int32_0;
                            class1_1 = null;
                            int_7++;
                            goto IL_05fd;
                        IL_05fd:
                            if (int_7 < class1_2.Length)
                            {
                                class1_1 = class1_2[int_7];
                                ChartPoint val6 = GearedValues<T>.smethod_3(bool_4, pointTracker_0, class1_1.Int32_0, class1_1.Prop_0);
                                val6.Gci = pointTracker_0.Gci;
                                val6.Instance = class1_1.Prop_0;
                                val6.Key = class1_1.Int32_0;
                                val6.SeriesView = iseriesView_0;
                                ipointEvaluator_0.Evaluate(class1_1.Int32_0, class1_1.Prop_0, val6);
                                if (int_6 != class1_1.Int32_0)
                                {
                                    int_3++;
                                    chartPoint_0 = val6;
                                    int_0 = 3;
                                    return true;
                                }
                                goto IL_05d7;
                            }
                            class1_2 = null;
                            class1_0 = new Class1<T>[2]
                            {
                        new Class1<T>
                        {
                            X = chartPoint_1.X,
                            Int32_0 = int_4,
                            Prop_0 = gparam_0,
                            Y = chartPoint_1.Y
                        },
                        new Class1<T>
                        {
                            X = chartPoint_1.X,
                            Int32_0 = int_4,
                            Prop_0 = gparam_0,
                            Y = chartPoint_1.Y
                        }
                            };
                            double_0 = double_3;
                            bool_6 = true;
                            goto IL_06ba;
                        IL_06c1:
                            if (chartPoint_1.X < class1_0[0].X)
                            {
                                class1_0[0].Y = chartPoint_1.Y;
                                class1_0[0].X = chartPoint_1.X;
                                class1_0[0].Prop_0 = gparam_0;
                                class1_0[0].Int32_0 = int_4;
                            }
                            if (chartPoint_1.X >= class1_0[1].X)
                            {
                                class1_0[1].Y = chartPoint_1.Y;
                                class1_0[1].X = chartPoint_1.X;
                                class1_0[1].Prop_0 = gparam_0;
                                class1_0[1].Int32_0 = int_4;
                            }
                            if (!double.IsNaN(chartPoint_1.X))
                            {
                                int_5++;
                            }
                            if (int_2 == ((NoisyCollection<T>)gearedValues).Count - 1)
                            {
                                ChartPoint val7 = GearedValues<T>.smethod_3(bool_4, pointTracker_0, int_4, gparam_0);
                                val7.Gci = pointTracker_0.Gci;
                                val7.Instance = gparam_0;
                                val7.Key = int_4;
                                val7.SeriesView = iseriesView_0;
                                ipointEvaluator_0.Evaluate(int_4, gparam_0, val7);
                                if (int_6 != int_4)
                                {
                                    int_3++;
                                    chartPoint_0 = val7;
                                    int_0 = 4;
                                    return true;
                                }
                            }
                            goto IL_033a;
                    }
                }
                catch
                {
                    //try-fault
                    ((IDisposable)this).Dispose();
                    throw;
                }
            }

            private void method_0()
            {
                int_0 = -1;
                if (ienumerator_0 != null)
                {
                    ienumerator_0.Dispose();
                }
            }

            [DebuggerHidden]
            void IEnumerator.Reset()
            {
                throw new NotSupportedException();
            }

            [DebuggerHidden]
            IEnumerator<ChartPoint> IEnumerable<ChartPoint>.GetEnumerator()
            {
                VerticalAlgorithm @class;
                if (int_0 == -2 && currentManagedThreadId == Environment.CurrentManagedThreadId)
                {
                    int_0 = 0;
                    @class = this;
                }
                else
                {
                    @class = new VerticalAlgorithm(0)
                    {
                        gearedValues_0 = gearedValues_0
                    };
                }
                @class.iseriesView_0 = iseriesView_1;
                @class.ipointEvaluator_0 = ipointEvaluator_1;
                @class.bool_4 = bool_5;
                @class.bool_0 = bool_1;
                @class.bool_2 = bool_3;
                return @class;
            }

            [DebuggerHidden]
            IEnumerator IEnumerable.GetEnumerator()
            {
                return ((IEnumerable<ChartPoint>)this).GetEnumerator();
            }
        }
        [CompilerGenerated]
        private sealed class Class22 : IEnumerable<ChartPoint>, IEnumerator<ChartPoint>, IEnumerable, IDisposable, IEnumerator
        {
            private int int_0;

            private ChartPoint chartPoint_0;

            private int int_1;

            public GearedValues<T> gearedValues_0;

            private ISeriesView iseriesView_0;

            public ISeriesView iseriesView_1;

            private int int_2;

            private bool bool_0;

            public bool bool_1;

            private bool bool_2;

            public bool bool_3;

            private IPointEvaluator<T> ipointEvaluator_0;

            public IPointEvaluator<T> ipointEvaluator_1;

            private ChartPoint chartPoint_1;

            private Func<double, double> func_0;

            private double double_0;

            private double double_1;

            private double double_2;

            private bool bool_4;

            public bool bool_5;

            private PointTracker pointTracker_0;

            private int int_3;

            private int int_4;

            private double double_3;

            private double double_4;

            private double double_5;

            private int int_5;

            private T gparam_0;

            private Class1<T>[] class1_0;

            private int int_6;

            private Class1<T> class1_1;

            private bool bool_6;

            private IEnumerator<T> ienumerator_0;

            private Class1<T>[] class1_2;

            private int int_7;

            ChartPoint IEnumerator<ChartPoint>.Current
            {
                [DebuggerHidden]
                get
                {
                    return chartPoint_0;
                }
            }

            object IEnumerator.Current
            {
                [DebuggerHidden]
                get
                {
                    return chartPoint_0;
                }
            }

            [DebuggerHidden]
            public Class22(int int_8)
            {
                int_0 = int_8;
                int_1 = Environment.CurrentManagedThreadId;
            }

            [DebuggerHidden]
            void IDisposable.Dispose()
            {
                int num = int_0;
                if (num == -3 || (uint)(num - 1) <= 3u)
                {

                    method_0();

                }
            }

            bool IEnumerator.MoveNext()
            {

                try
                {
                    int num = int_0;
                    GearedValues<T> gearedValues = gearedValues_0;
                    ChartPoint val5;
                    switch (num)
                    {
                        default:
                            return false;
                        case 0:
                            {
                                int_0 = -1;
                                Class21 CS_0024_003C_003E8__locals0 = new Class21();
                                switch (gearedValues.Quality)
                                {
                                    default:
                                        throw new ArgumentOutOfRangeException();
                                    case Quality.Low:
                                        double_5 = 10.0;
                                        break;
                                    case Quality.Medium:
                                        double_5 = 5.0;
                                        break;
                                    case Quality.High:
                                        double_5 = 2.0;
                                        break;
                                    case Quality.Highest:
                                        double_5 = 1.0;
                                        break;
                                }
                                int_4 = 0;
                                double_0 = 0.0;
                                class1_0 = new Class1<T>[2]
                                {
                        new Class1<T>
                        {
                            Y = double.PositiveInfinity
                        },
                        new Class1<T>
                        {
                            Y = double.NegativeInfinity
                        }
                                };
                                pointTracker_0 = gearedValues.GetTracker(iseriesView_0);
                                int_5 = 0;
                                AxisCore val = iseriesView_0.Model.Chart.AxisX[iseriesView_0.ScalesXAt];
                                CS_0024_003C_003E8__locals0.double_1 = val.TopLimit;
                                CS_0024_003C_003E8__locals0.double_2 = iseriesView_0.Model.Chart.DrawMargin.Width + iseriesView_0.Model.Chart.DrawMargin.Left;
                                double botLimit = val.BotLimit;
                                double left = iseriesView_0.Model.Chart.DrawMargin.Left;
                                double num2 = botLimit - CS_0024_003C_003E8__locals0.double_1;
                                CS_0024_003C_003E8__locals0.double_0 = (left - CS_0024_003C_003E8__locals0.double_2) / ((num2 == 0.0) ? double.MinValue : num2);
                                func_0 = (double double_3) => CS_0024_003C_003E8__locals0.double_0 * (double_3 - CS_0024_003C_003E8__locals0.double_1) + CS_0024_003C_003E8__locals0.double_2;
                                chartPoint_1 = new ChartPoint();
                                int_6 = -1;
                                double_1 = (double.IsNaN(val.MinValue - val.S) ? double.MinValue : (val.MinValue - val.S));
                                double_2 = (double.IsNaN(val.MaxValue + val.S) ? double.MaxValue : (val.MaxValue + val.S));
                                bool_6 = false;
                                int_3 = 0;
                                int_2 = -1;
                                ienumerator_0 = ((NoisyCollection<T>)gearedValues).GetEnumerator();
                                int_0 = -3;
                                goto IL_0865;
                            }
                        case 1:
                            int_0 = -3;
                            int_6 = int_4;
                            double_0 = double_3;
                            int_4++;
                            goto IL_0865;
                        case 2:
                            int_0 = -3;
                            double_0 = double_3;
                            int_6 = int_4;
                            class1_0 = new Class1<T>[2]
                            {
                        new Class1<T>
                        {
                            Y = double.PositiveInfinity
                        },
                        new Class1<T>
                        {
                            Y = double.NegativeInfinity
                        }
                            };
                            goto IL_06ba;
                        case 3:
                            int_0 = -3;
                            goto IL_05d7;
                        case 4:
                            {
                                int_0 = -3;
                                goto IL_033a;
                            }
                        IL_033a:
                            int_4++;
                            gparam_0 = default(T);
                            goto IL_0865;
                        IL_06ba:
                            int_5 = 0;
                            goto IL_06c1;
                        IL_0865:
                            while (true)
                            {
                                if (ienumerator_0.MoveNext())
                                {
                                    gparam_0 = ienumerator_0.Current;
                                    int_2++;
                                    if (bool_0)
                                    {
                                        IObservableChartPoint val2 = (IObservableChartPoint)(object)gparam_0;
                                        if (val2 != null)
                                        {
                                            val2.PointChanged -= gearedValues.method_7;
                                            val2.PointChanged += gearedValues.method_7;
                                        }
                                    }
                                    if (bool_2)
                                    {
                                        INotifyPropertyChanged notifyPropertyChanged = (INotifyPropertyChanged)(object)gparam_0;
                                        if (notifyPropertyChanged != null)
                                        {
                                            notifyPropertyChanged.PropertyChanged -= gearedValues.UpdateAllSeriess;
                                            notifyPropertyChanged.PropertyChanged += gearedValues.UpdateAllSeriess;
                                        }
                                    }
                                    ipointEvaluator_0.Evaluate(int_4, gparam_0, chartPoint_1);
                                    double_3 = func_0(chartPoint_1.X);
                                    double_4 = Math.Abs(double_0 - double_3);
                                    if (!(chartPoint_1.X < double_1) && !(chartPoint_1.X > double_2))
                                    {
                                        break;
                                    }
                                    int_4++;
                                    continue;
                                }
                                method_0();
                                ienumerator_0 = null;
                                Series val3 = (Series)iseriesView_0;
                                if (!bool_6 && int_3 <= 100)
                                {
                                    if (gearedValues.PointGeometry != null)
                                    {
                                        ((Series)iseriesView_0).PointGeometry = gearedValues.PointGeometry;
                                    }
                                }
                                else
                                {
                                    Geometry pointGeometry = ((Series)iseriesView_0).PointGeometry;
                                    if (pointGeometry != null)
                                    {
                                        gearedValues.PointGeometry = pointGeometry;
                                    }
                                    val3.PointGeometry = null;
                                }
                                val3.Model.Chart.View.LoadLegend();
                                return false;
                            }
                            if (int_2 != 0)
                            {
                                if (double_4 > double_5 || int_2 == ((NoisyCollection<T>)gearedValues).Count - 1)
                                {
                                    int num3 = int_5;
                                    if ((uint)num3 > 1u)
                                    {
                                        Class1<T>[] array = class1_0.OrderBy((Class1<T> class1_0) => class1_0.X).ToArray();
                                        class1_2 = array;
                                        int_7 = 0;
                                        goto IL_05fd;
                                    }
                                    ChartPoint val4 = GearedValues<T>.smethod_3(bool_4, pointTracker_0, int_4, gparam_0);
                                    val4.Gci = pointTracker_0.Gci;
                                    val4.Instance = gparam_0;
                                    val4.Key = int_4;
                                    val4.SeriesView = iseriesView_0;
                                    ipointEvaluator_0.Evaluate(int_4, gparam_0, val4);
                                    int_3++;
                                    chartPoint_0 = val4;
                                    int_0 = 2;
                                    return true;
                                }
                                goto IL_06c1;
                            }
                            val5 = GearedValues<T>.smethod_3(bool_4, pointTracker_0, int_4, gparam_0);
                            val5.Gci = pointTracker_0.Gci;
                            val5.Instance = gparam_0;
                            val5.Key = int_4;
                            val5.SeriesView = iseriesView_0;
                            ipointEvaluator_0.Evaluate(int_4, gparam_0, val5);
                            int_3++;
                            chartPoint_0 = val5;
                            int_0 = 1;
                            return true;
                        IL_05d7:
                            int_6 = class1_1.Int32_0;
                            class1_1 = null;
                            int_7++;
                            goto IL_05fd;
                        IL_05fd:
                            if (int_7 < class1_2.Length)
                            {
                                class1_1 = class1_2[int_7];
                                ChartPoint val6 = GearedValues<T>.smethod_3(bool_4, pointTracker_0, class1_1.Int32_0, class1_1.Prop_0);
                                val6.Gci = pointTracker_0.Gci;
                                val6.Instance = class1_1.Prop_0;
                                val6.Key = class1_1.Int32_0;
                                val6.SeriesView = iseriesView_0;
                                ipointEvaluator_0.Evaluate(class1_1.Int32_0, class1_1.Prop_0, val6);
                                if (int_6 != class1_1.Int32_0)
                                {
                                    int_3++;
                                    chartPoint_0 = val6;
                                    int_0 = 3;
                                    return true;
                                }
                                goto IL_05d7;
                            }
                            class1_2 = null;
                            class1_0 = new Class1<T>[2]
                            {
                        new Class1<T>
                        {
                            Y = chartPoint_1.Y,
                            Int32_0 = int_4,
                            Prop_0 = gparam_0,
                            X = chartPoint_1.X
                        },
                        new Class1<T>
                        {
                            Y = chartPoint_1.Y,
                            Int32_0 = int_4,
                            Prop_0 = gparam_0,
                            X = chartPoint_1.X
                        }
                            };
                            double_0 = double_3;
                            bool_6 = true;
                            goto IL_06ba;
                        IL_06c1:
                            if (chartPoint_1.Y < class1_0[0].Y)
                            {
                                class1_0[0].Y = chartPoint_1.Y;
                                class1_0[0].X = chartPoint_1.X;
                                class1_0[0].Prop_0 = gparam_0;
                                class1_0[0].Int32_0 = int_4;
                            }
                            if (chartPoint_1.Y >= class1_0[1].Y)
                            {
                                class1_0[1].Y = chartPoint_1.Y;
                                class1_0[1].X = chartPoint_1.X;
                                class1_0[1].Prop_0 = gparam_0;
                                class1_0[1].Int32_0 = int_4;
                            }
                            if (!double.IsNaN(chartPoint_1.Y))
                            {
                                int_5++;
                            }
                            if (int_2 == ((NoisyCollection<T>)gearedValues).Count - 1)
                            {
                                ChartPoint val7 = GearedValues<T>.smethod_3(bool_4, pointTracker_0, int_4, gparam_0);
                                val7.Gci = pointTracker_0.Gci;
                                val7.Instance = gparam_0;
                                val7.Key = int_4;
                                val7.SeriesView = iseriesView_0;
                                ipointEvaluator_0.Evaluate(int_4, gparam_0, val7);
                                if (int_6 != int_4)
                                {
                                    int_3++;
                                    chartPoint_0 = val7;
                                    int_0 = 4;
                                    return true;
                                }
                            }
                            goto IL_033a;
                    }
                }
                catch
                {
                    //try-fault
                    ((IDisposable)this).Dispose();
                    throw;
                }
            }

            private void method_0()
            {
                int_0 = -1;
                if (ienumerator_0 != null)
                {
                    ienumerator_0.Dispose();
                }
            }

            [DebuggerHidden]
            void IEnumerator.Reset()
            {
                throw new NotSupportedException();
            }

            [DebuggerHidden]
            IEnumerator<ChartPoint> IEnumerable<ChartPoint>.GetEnumerator()
            {
                Class22 @class;
                if (int_0 == -2 && int_1 == Environment.CurrentManagedThreadId)
                {
                    int_0 = 0;
                    @class = this;
                }
                else
                {
                    @class = new Class22(0)
                    {
                        gearedValues_0 = gearedValues_0
                    };
                }
                @class.iseriesView_0 = iseriesView_1;
                @class.ipointEvaluator_0 = ipointEvaluator_1;
                @class.bool_4 = bool_5;
                @class.bool_0 = bool_1;
                @class.bool_2 = bool_3;
                return @class;
            }

            [DebuggerHidden]
            IEnumerator IEnumerable.GetEnumerator()
            {
                return ((IEnumerable<ChartPoint>)this).GetEnumerator();
            }
        }
    }
}
